package com.yunxin.core.application.assembler;

import com.yunxin.core.application.command.user.UserAuthCommand;
import com.yunxin.core.application.command.user.UserInfoPageCommand;
import com.yunxin.core.application.command.user.UserRegisterCommand;
import com.yunxin.core.application.command.user.UserVisitorInfoCommand;
import com.yunxin.core.application.dto.user.UserInfoPageDTO;
import com.yunxin.core.domain.model.user.UserAuth;
import com.yunxin.core.domain.model.user.UserInfo;
import com.yunxin.core.domain.model.user.UserVisitorInfo;
import com.yunxin.core.infra.persistence.entity.user.UserInfoDO;
import com.yunxin.core.infra.persistence.entity.user.query.condition.UserPageCondition;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * @author zero°
 * @since 2023-06-02
 */
@Mapper(componentModel = "spring")
public interface UserInfoAssembler {
    /**
     * entity 转 dto
     * @param entity entity
     * @return UserPageDTO
     */
    @Mapping(target = "userPhone", source = "phone")
    UserInfoPageDTO toUserPageDTO(UserInfoDO entity);

    /**
     * command 转 entity
     * @param command command
     * @return UserBuryingPointData
     */
    UserVisitorInfo formUserVisitorInfoCommand(UserVisitorInfoCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return UserInfo
     */
    UserInfo formUserRegisterCommand(UserRegisterCommand command);

    /**
     * command 转 entity
     * @param command command
     * @return UserAuth
     */
    UserAuth formUserAuthCommand(UserAuthCommand command);

    /**
     * command 转 condition
     * @param command command
     * @return UserPageCondition
     */
    @Mapping(target = "startRegisterTime", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateByStartTimeStr(command.getStartRegisterTime()))")
    @Mapping(target = "endRegisterTime", expression = "java(com.yunxin.core.utils.infra.utils.DateFormatUtils.X.getDateByEndTimeStr(command.getEndRegisterTime()))")
    UserPageCondition formUserPageCommand(UserInfoPageCommand command);
}
